package com.yinhe.group.whd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yinhe.group.whd.domain.YhMap;
import com.yinhe.group.whd.service.IYhMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;

import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 地图信息Controller
 * 
 * @author yinhe
 * @date 2023-02-13
 */
@RestController
@RequestMapping("/system/map")
public class YhMapController extends BaseController
{
    @Autowired
    private IYhMapService yhMapService;

    /**
     * 查询地图信息列表
     */

    @GetMapping("/list")
    public TableDataInfo list(YhMap yhMap)
    {
        startPage();
        List<YhMap> list = yhMapService.selectYhMapList(yhMap);
        return getDataTable(list);
    }



    /**
     * 导入
     */
    @Log(title = "地图", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:map:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YhMap> util = new ExcelUtil<YhMap>(YhMap.class);
        List<YhMap> contractList = util.importExcel(file.getInputStream());
        String message = yhMapService.importMap(contractList, updateSupport);
        return AjaxResult.success(message);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YhMap> util = new ExcelUtil<YhMap>(YhMap.class);
        util.importTemplateExcel(response, "导入数据");
    }

    /**
     * 导出地图信息列表
     */

    @Log(title = "地图信息", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:map:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhMap yhMap)
    {
        List<YhMap> list = yhMapService.selectYhMapList(yhMap);
        ExcelUtil<YhMap> util = new ExcelUtil<YhMap>(YhMap.class);
        util.exportExcel(response, list, "地图信息数据");
    }

    /**
     * 获取地图信息详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhMapService.selectYhMapById(id));
    }
    /**
     * 新增地图信息
     */

    @Log(title = "地图信息", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('system:map:add')")
    @PostMapping
    public AjaxResult add(@RequestBody YhMap yhMap)
    {
        return toAjax(yhMapService.insertYhMap(yhMap));
    }

    /**
     * 修改地图信息
     */

    @Log(title = "地图信息", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('system:map:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody YhMap yhMap)
    {
        return toAjax(yhMapService.updateYhMap(yhMap));
    }

    /**
     * 删除地图信息
     */

    @Log(title = "地图信息", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('system:map:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhMapService.deleteYhMapByIds(ids));
    }
}
